package cn.gmph.blog.admin.service.sys.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gmph.blog.admin.service.sys.dao.helper.OptionsProvider;
import cn.gmph.blog.admin.service.sys.entity.OptionsDO;

import java.util.List;;

public interface OptionsDAO {

    @Results({@Result( column = "option_id",property = "optionId"),@Result( column = "option_name",property = "optionName"),@Result( column = "option_value",property = "optionValue") })
    @Select("SELECT * FROM wp_options WHERE id = #{id}")
    public OptionsDO getById(@Param("id") int id);

    @Insert("INSERT into wp_options(option_id,option_name,option_value,autoload) VALUES (#{optionId},#{optionName},#{optionValue},#{autoload})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insert(OptionsDO options);

    @Delete("DELETE FROM wp_options WHERE id = #{id}")
    public int deleteById(@Param("id") int id);

    @UpdateProvider(type = OptionsProvider.class, method = "update")
    public int update(@Param("options") OptionsDO  options);

    @Results({@Result( column = "option_id",property = "optionId"),@Result( column = "option_name",property = "optionName"),@Result( column = "option_value",property = "optionValue") })
    @SelectProvider(type = OptionsProvider.class, method = "pageList")
    public List<OptionsDO> pageList(@Param("options") OptionsDO options, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @SelectProvider(type = OptionsProvider.class, method = "pageListCount")
    public Integer pageListCount(@Param("options") OptionsDO options);

}